﻿using System;
using System.Windows.Forms;
using Webitel.Properties;

namespace Webitel
{
	public static class Tray
	{
		private static NotifyIcon _notifyIcon;

		public static void ShowMessage(string tipTitle, string tipText)
		{
			_notifyIcon.ShowBalloonTip(10, tipTitle, tipText, ToolTipIcon.None);
		}

		public static void Initialize()
		{
			if (_notifyIcon == null)
			{
				_notifyIcon = new NotifyIcon();
			}
			_notifyIcon.ContextMenu = new ContextMenu();
			_notifyIcon.ContextMenu.MenuItems.Add(new MenuItem(Resources.Settings, Settings_onClick));
			_notifyIcon.ContextMenu.MenuItems.Add(new MenuItem(Resources.Exit, Exit_onClick));
			_notifyIcon.MouseDoubleClick += notifyIcon_MouseDoubleClick;
			_notifyIcon.Visible = true;
			_notifyIcon.Icon = Resources.Phone2_Grey;
		}

		private static void Settings_onClick(object sender, EventArgs e)
		{
			
		}

		public static void Hide()
		{
			_notifyIcon.Visible = false;
		}

		private static void Exit_onClick(object sender, EventArgs e)
		{
			_notifyIcon.Icon = Resources.Phone2_Grey;
			MainWindow.get_instance().Close();
			_notifyIcon.Visible = false;
			Environment.Exit(0);
		}

		private static void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if (MainWindow.get_instance().IsVisible)
			{
				MainWindow.get_instance().Hide();
			}
			else
			{
				MainWindow.get_instance().Show();
			}
		}

	}
}
